<!DOCTYPE HTML>
<html>
<head>
<?php
	include("components/helper.php");
	include("components/metadata.php");
?>
<title>40Towers - Home Page</title>
<link rel="stylesheet" href="css/global.css" />
<link rel="stylesheet" href="css/news_item.css" />
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<?php
	include("components/analytics.php");
	include("components/database.php");	
	
	$get_id = $_GET["id"];
?>

<!-- Place this render call where appropriate -->
<script type="text/javascript">
  window.___gcfg = {lang: 'en-GB'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>

</head>
<body>

<div id="page">
    <?php
		include("components/header.php");
		include("components/nav.php");
	?>
    
    <div>
    <section class="group">
        <h1>The full story</h1>
        <article>
            <header>
            	<?php 
					if ($result = $mysqli->query("SELECT * FROM NewsItem WHERE id=$get_id ORDER BY postDate DESC")) { 
						while($obj = $result->fetch_object()){ 
							$id = $obj->id; 
							$title = $obj->title; 
							$bodyCopy = $obj->bodyCopy;
	//						$bodyCopy = substr($obj->bodyCopy, 0, strpos($obj->bodyCopy, '.', 300)) . ". <a href='". $id ."'>Full Story...</a>"; 
							$postDate = $obj->postDate;
							$datetime = str_replace(" ", "T", $postDate);
							
							$sourceUrl = $obj->sourceUrl;
							
							$imageUrl = "img/missing_image.gif";
							
							if ($result2 = $mysqli->query("SELECT * FROM image WHERE id=".$obj->imageId )) { 
								while($obj2 = $result2->fetch_object()){ 
									$imageUrl = "img/" . $obj2->url;
								}
							}
				?>
                
                <h3>
					<a href='javascript:history.back();'>Back&nbsp;&laquo;</a>
                </h3>
                <h2><?php echo replaceSpeechMarks($title); ?></h2>
                
                <p>
					<?php if ( $imageUrl != "img/missing_image.gif" ) { ?>
                        <img src="<?= $imageUrl; ?>" alt="<?php echo replaceSpeechMarks($title); ?>" />
                    <?php } ?>
                    <?php echo nl2br(replaceSpeechMarks($bodyCopy)); ?>
                </p>
				
            </header>
            <footer>
            <h3>
					<?php if ( $sourceUrl!="#" ) { ?>
	                    <a href="<?= $sourceUrl; ?>" target="_blank">Source</a>
	                <?php } ?>
	            </h3>
            <p>Posted on <time datetime="<?= $datetime; ?>"><?php echo date('l jS \of F Y', strtotime($postDate) ); ?></time></p>
				
			</footer>
			<hr>
			<div id="social">
            
			<iframe src="//www.facebook.com/plugins/like.php?href&amp;send=false&amp;layout=button_count&amp;width=150&amp;show_faces=true&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:21px;" allowTransparency="true"></iframe>
            
            <!-- Place this tag where you want the +1 button to render -->
			<g:plusone size="medium"></g:plusone>

			<a href="https://twitter.com/share" class="twitter-share-button" data-via="40Towers">Tweet</a>
			<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
			
			<a href="https://twitter.com/40Towers" class="twitter-follow-button" data-show-count="true">Follow @40Towers</a>
			<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
			
			</div>
				<?php
                        } 
                    }
                ?>
        </article>
    </section>
    </div>
    <?php
		include("components/rightBanners.php");
	?>
</div>
<?php
	include("components/footer.php");
?>

</body>
</html>
